package com.whosly.mysql.protocol.packet.jdbc;

import java.sql.Types;

/**
 * 字段类型及标识定义
 *
 * @see  FieldsProtocol
 * @see  FieldsProtocolType
 *
 * @author 风杨
 * @see <a href="yueny09@163.com">mailTo: yueny09@163.com</a>
 */
@Deprecated
public class MysqlDefs {

    public static final int FIELD_TYPE_DECIMAL = FieldsProtocol.FIELD_TYPE_DECIMAL;

    public static final int FIELD_TYPE_TINY = FieldsProtocol.FIELD_TYPE_TINY;

    public static final int FIELD_TYPE_SHORT = FieldsProtocol.FIELD_TYPE_SHORT;

    public static final int FIELD_TYPE_LONG = FieldsProtocol.FIELD_TYPE_LONG;

    public static final int FIELD_TYPE_FLOAT = FieldsProtocol.FIELD_TYPE_FLOAT;

    public static final int FIELD_TYPE_DOUBLE = FieldsProtocol.FIELD_TYPE_DOUBLE;

    public static final int FIELD_TYPE_NULL = 6;

    public static final int FIELD_TYPE_TIMESTAMP = 7;

    public static final int FIELD_TYPE_LONGLONG = 8;

    public static final int FIELD_TYPE_INT24 = 9;

    public static final int FIELD_TYPE_DATE = 10;

    public static final int FIELD_TYPE_TIME = 11;

    public static final int FIELD_TYPE_DATETIME = 12;

    public static final int FIELD_TYPE_YEAR = 13;

    public static final int FIELD_TYPE_NEWDATE = 14;

    public static final int FIELD_TYPE_VARCHAR = 15;

    public static final int FIELD_TYPE_BIT = 16;


    public static final int FIELD_TYPE_NEW_DECIMAL = 246;

    public static final int FIELD_TYPE_ENUM = 247;

    public static final int FIELD_TYPE_SET = 248;

    public static final int FIELD_TYPE_TINY_BLOB = 249;

    public static final int FIELD_TYPE_MEDIUM_BLOB = 250;

    public static final int FIELD_TYPE_LONG_BLOB = 251;

    public static final int FIELD_TYPE_BLOB = FieldsProtocol.FIELD_TYPE_BLOB;

    public static final int FIELD_TYPE_VAR_STRING = 253;

    public static final int FIELD_TYPE_STRING = 254;

    public static final int FIELD_TYPE_GEOMETRY = 255;



    public static final long LENGTH_BLOB = 65535;

    public static final long LENGTH_MEDIUMBLOB = 16777215;

    public static final long LENGTH_LONGBLOB = 4294967295L;

    public static final int NO_CHARSET_INFO = -1;

    public static final byte OPEN_CURSOR_FLAG = 1;

    /**
     *
     * @param sqlType
     * @param isRawDatetime
     * @return
     */
    @Deprecated
    public static int javaTypeMysql(int sqlType, final boolean isRawDatetime) {

        switch (sqlType) {
            case Types.NULL:
                return MysqlDefs.FIELD_TYPE_NULL;

            case Types.BOOLEAN:
                return MysqlDefs.FIELD_TYPE_TINY;

            case Types.TINYINT:
                return MysqlDefs.FIELD_TYPE_TINY;

            case Types.SMALLINT:
                return MysqlDefs.FIELD_TYPE_SHORT;

            case Types.INTEGER:
                return MysqlDefs.FIELD_TYPE_LONG;


            case Types.NUMERIC:   // TODO
                return MysqlDefs.FIELD_TYPE_LONG;

            case Types.REAL: // TODO
            case Types.FLOAT:
                return MysqlDefs.FIELD_TYPE_FLOAT;

            case Types.DOUBLE:
                return MysqlDefs.FIELD_TYPE_DOUBLE;

            case Types.DECIMAL:
                return MysqlDefs.FIELD_TYPE_NEW_DECIMAL;

            case Types.BIGINT:
                return MysqlDefs.FIELD_TYPE_LONGLONG;





                // TODO ALL
            case Types.CHAR:
                return MysqlDefs.FIELD_TYPE_STRING;

            case Types.VARCHAR:
                return MysqlDefs.FIELD_TYPE_VAR_STRING;

            case Types.BIT:
                return MysqlDefs.FIELD_TYPE_BIT;
            case Types.CLOB:
                return MysqlDefs.FIELD_TYPE_VAR_STRING;
            case Types.BLOB:
                return MysqlDefs.FIELD_TYPE_BLOB;

            case Types.TIME:
                return MysqlDefs.FIELD_TYPE_TIME;

            case Types.DATE:
                return MysqlDefs.FIELD_TYPE_DATE;

            case Types.TIMESTAMP:
                if (isRawDatetime) {
                    return MysqlDefs.FIELD_TYPE_DATETIME;
                } else {
                    return MysqlDefs.FIELD_TYPE_TIMESTAMP;
                }

            case Types.VARBINARY:
                return MysqlDefs.FIELD_TYPE_TINY_BLOB;

            case Types.LONGVARBINARY:
                return MysqlDefs.FIELD_TYPE_BLOB;

            case Types.BINARY:
                return MysqlDefs.FIELD_TYPE_BLOB;

            case Types.ARRAY:
                return MysqlDefs.FIELD_TYPE_VAR_STRING;

            default:
                return Types.VARCHAR;
        }

    }

}
